package user;

import java.util.Scanner;

public class Login {
    public User login() {
        System.out.print("请输入你的姓名:");
        Scanner scanner=new Scanner(System.in);
        String name=scanner.nextLine();
        System.out.print("请输入你的身份: 1->管理员 0->普通用户  ");
        int choice=scanner.nextInt();
        if(choice==1) {
            AdminUserException adminUserException=new AdminUserException();
            try {
                adminUserException.adminUserNameException(name);
            }catch (AdminUserException e) {
                e.printStackTrace();
                System.out.println("管理员用户名输入有误!");
                return null;
            }
            return new AdminUser(name);
        }else {
            NormalUserNameException normalUserNameException=new NormalUserNameException();
            try {
                normalUserNameException.normalUserNameException(name);
            }catch (NormalUserNameException e) {
                e.printStackTrace();
                System.out.println("普通用户名输入有误!");
                return null;
            }
            return new NormalUser(name);
        }
    }
}
